package com.andrewdashin.twit2jabber.dao.impl;

import com.andrewdashin.twit2jabber.dao.UserDao;
import com.andrewdashin.twit2jabber.domain.User;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

/**
 * User: dashin
 * Date: 03.12.2009
 * Time: 9:20:28
 */
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

    private Criteria getCriteria() {
        return getSession().createCriteria(User.class);
    }

    @Override
    @SuppressWarnings("unchecked")
    public List<User> findAllActive() {
        return getCriteria().add(Restrictions.eq("active", true)).list();
    }

    @Override
    public User findByJabberUserName(String jabberUserName) {
        return (User) getCriteria().add(Restrictions.eq("jabberUserName", jabberUserName)).uniqueResult();
    }
}
